/*
Another game of life with SDL renderer.
Copyright (C) 2009-2010  Julien CLEMENT (andematunum@gmail.com)
*/
/*
	This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _Matrix_h_
#define _Matrix_h_

// Forward declarations
class Cell;
class MatrixRenderer;

class Matrix {
	
	friend class SDLMatrixRenderer;

	public:
		// Create a new empty game of life matrix
		Matrix (unsigned int w=16, unsigned int h=16, bool wrap=true);

		// Frees the memory allocated for the cells
		~Matrix ();

		// Initializes the matrix randomly
		void initRandom (void);

		// Initializes the matrix randomly using rgb colors
		void initRandomColor (void);

		// Advance to the next step
		// Returns true if something changed,
		// else return false.
		bool life (void);

		// Get the cell at (r,c)
		// return NULL if we don't wrap and
		// the requested cell is out of bounds.
		Cell *getCell (int r, int c);

		// Specific inits
		void initGlider		(int x=0, int y=0);
		void initOscillator	(int x=0, int y=0);

		Cell ** getData (void);

		void swap (void);

	private:
		// Contents of the matrix
		Cell ** _cells;

		// Contents of the matrix at next step
		Cell ** _buffer;

		// Current memory pointer
		Cell ** _memory;

		// Do we use colors
		bool _usecolors;

		// Do we wrap on borders
		bool _wrap;

		unsigned int _w;
		unsigned int _h;

};

#endif

